home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / PROLOG / HUMBOLT / HUMBOLTS / _files / _humboltsr / unixio._c < prev    next >
Text File  |  1990-06-10  |  2KB  |  125 lines

  1. struct { int dummy ; } __extradata;
  2.  
  3. #include   <stdio.h>
  4. #include   <stdlib.h>
  5. #include   <kernel.h>
  6.  
  7. static char *opentab[] = { "r", "w" "r+" };
  8. static int  unixio_raw = 1;
  9. static int  activetab[_SYS_OPEN];
  10.  
  11. #define SETUP if( unixio_raw ) setup_unixio()
  12.  
  13. static void setup_unixio(void)
  14. {
  15. int i;
  16.     for( i = 0; i < _SYS_OPEN; ++i )
  17.        activetab[i]=0;
  18. /*    setvbuf( stdin , NULL, _IONBF, (size_t)0 );
  19.     setvbuf( stdout , NULL, _IONBF, (size_t)0 );
  20.     setvbuf( stderr , NULL, _IONBF, (size_t)0 ); */
  21.     unixio_raw = 0;
  22. }
  23.  
  24.  
  25. int open(char *name, int mode)
  26. {
  27. FILE  *hndle;
  28.       SETUP;
  29.       if( mode < 0 || mode > 2 )
  30.           return -1;
  31.       hndle = fopen( name, opentab[mode] );
  32.       if( hndle == NULL )
  33.           return -1;
  34.       setvbuf( hndle, NULL, _IONBF, (size_t)0 );
  35.       return hndle - __iob;
  36. }
  37.  
  38. int creat(char *name, int access)
  39. {
  40.  
  41. FILE  *hndle;
  42.       SETUP;
  43.       hndle = fopen( name, "w+" );
  44.       if( hndle == NULL )
  45.           return -1;
  46.       setvbuf( hndle, NULL, _IONBF, (size_t) 0 );
  47.       return hndle - __iob;
  48. }
  49.  
  50.     
  51. int close(int strmno)
  52. {
  53.        SETUP;
  54.        return fclose( &__iob[strmno] );
  55. }
  56.  
  57. int unlink(char *name)
  58. {
  59.        return remove( name );
  60. }
  61.  
  62. int isatty(int strmno)
  63. {
  64. FILE  *hndle;
  65.        SETUP;
  66.        hndle = &__iob[strmno];
  67.        return hndle == stdin || hndle == stdout || hndle == stderr;
  68. }
  69.  
  70. int write(int strmno, char *buf, int len)
  71. {
  72. FILE  *hndle;
  73. int   written;
  74.       SETUP;
  75.       hndle = &__iob[strmno];
  76.       written = (int) fwrite( buf, (size_t) 1, (size_t) len, hndle );
  77.       if( fflush(hndle) )
  78.           return -1;
  79.       return written;
  80. }
  81.  
  82.  
  83.  
  84. int read(int strmno, char *buf, int len)
  85. {
  86. FILE  *hndle;
  87. int   readden;
  88. int   i = 0;
  89. char  *ret;
  90.  
  91.       SETUP;
  92.       hndle = &__iob[strmno];
  93.       if( hndle == stdin ) {
  94.         if( fgets( buf, len, stdin ) == NULL )
  95.           readden = 0;
  96.         else
  97.           readden = strlen( buf );
  98.       } else {
  99.         readden = (int) fread( buf, (size_t) 1, (size_t) len, hndle );
  100.       }
  101.  
  102.       if( ferror( hndle ) )
  103.           return -1;
  104.       else
  105.           return readden;
  106.  
  107. }
  108.  
  109. int fseektab[]={ SEEK_SET, SEEK_CUR, SEEK_END };
  110.  
  111. int lseek(int strmno, long position, int whence)
  112. {
  113. FILE *hndle;
  114.      SETUP;
  115.      hndle = &__iob[strmno];
  116.      return fseek( hndle, position, fseektab[whence] );
  117. }
  118.  
  119. void prt(char *s)
  120. {
  121.      fputs( s, stderr );
  122. }
  123.  
  124.  
  125.